package com.cdut.logistics.model.dao.datacentre;

import java.util.Date;

import com.cdut.logistics.model.entity.datacentre.BaseArea;
import com.jfinal.plugin.activerecord.Db;

/**  
 * @ClassName: Area 
 * @Description: 操作数据库 
 * @author wxt.asus
 * @date 2018年1月26日 上午9:13:52    
 */
public class Area extends BaseArea<Area>{
	private static final long serialVersionUID = 1L;
	public static Area dao = new Area();
	public static String table = "area";
	public String baseSql = " and is_use = 1";
	public String sql1 = "SELECT "+
			"area.id,"+
			"area.`name`,"+
			"school.name as 'school_name' "+
			"FROM area  join school "+
			"ON area.school_id=school.id "+
			"AND area.is_use = 1 "+
			"AND school.is_use = 1 "+
			"AND area.`name` like ?";
	public String sql2 = "UPDATE area set name =?, updated=? where id =?"+ baseSql;
	public String sql3 = "UPDATE area set is_use =?, updated=? where id =?"+ baseSql;
	/**  
	 * @Title: save  
	 * @Description: 新增区域
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void save(Area area) {
		area.set("created", new Date());
		area.set("updated", new Date());
		area.set("is_use", 1);
		area.set("active", 1);
		area.save();
	}

	/**  
	 * @Title: update  
	 * @Description: 修改区域
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void update(Area area) {
		area.set("updated", new Date());
		Db.update(sql2,area.getName(),area.getUpdated(),area.getId());
	}

	/**  
	 * @Title: remove  
	 * @Description: 删除区域
	 * @author wxt.xia
	 * @param id
	 * @throws  
	 */
	public void remove(int id) {
		Db.update(sql3,0,new Date(),id);
	}
}
